refactored some code
fixed merge conflicts