Refatored. Added more tests