Refactored long lines, added more helper functions