code.c

Logic is improved and code is now more reliable