Cleaned up the code and made it shorter.