Reorganize functions to please jsLint