minor changes  and refactored code