refactored a few lines to make it more readable