Refactored and added some basic tests