cleaned up the code and took out unnecessary waits