refactored function names, reorganized a little