Cleaned up the code a little with messages and comments