improved readability and a bit of refactoring