Slight rearranging.
More cleanup. Started to use exceptions for better error handling.