Clean up styles and code, and add any necessary error checking