Clean up and code improvement