Code cleanup.
Better error handling.