cleanups; generalized some functions and moved them into the 'functions' file