reimplemented logic and isolated bug in main loop
fixed main merge conflict