Reworked existing code to make better use of included libraries