Added several support functions and translated several functions from pseudo code to working code