Code cleanup and changes based on comments