Updated to functions

Retrofitted the broken subroutine system to a more modern function
system.