Improved logging and added some hacky synchronization