Cleaned up the code a bit for readability