refactored code to prevent duplication, allow for more flexibility, also rewrote tests for new methods