Added message boxes and cleaned up code