Added message box error checking and fixed several coding style issues