Cleaned up the code a bit before things are final.