beautified and cleaned code a bit