Clean up and some bug fixes