refactored a little to more readable code