refactored things a bit