Compacted the code a bit