Code cleanup/optimisation and bug fixes

Fixed collisions and general code optimisations