Bugfix for rounded cost + major cleanup