More refactoring

Added more exception handling and cleaned up. Restricted some classes to
package scope and made some final.