improved coding style and refactored code a little bit