refactored some code, added some more functions