Ready for submission

Functions reworked to improve logic and reduce calculations.