Do some cleaning and fix broken calculations