Cleaning and simplification of code