refactored some code much more efficient!