Cleanup and improve of code