cleanups and maths stuff