Polished the code a bit