TECS-WIP : Cleaned up code and replaced in-line code with functions