code clean up and simple errors