Simplified the code a bit