Cleaned up code a bit. Commented for presentation