tweaks
Refactored and added tests