fixing concurrency issues
cleaning up code