Handling threading better with @sync