Added Tests and Refactored