Major refactoring, swapping out floating point variables for intigers. Some tidying still to do but more stable.