refactored and simplified some code