Final clean up and simplification of code