How to write a code correctly