Fix code logic

Cleaning up code logic