Added some tests and refactored methods