code refactoring: group related functions together. Close #18