refactoring code according to @w33ble pr code review comments