Cleanup
Review semaphore
Better thread support