Optimizing code, fixing !rem