refactoring some methods and adding some more functionality