code was little bit refactored