Cleaned up some loose code and convert the functions to locals.