Cleaning up duplication, adding tests