refactored code
fixed merge issues