Prettified and refactored code a bit