Cleaned up code and added debug info to fix synchronization issue