Clean up and fixing bugs