Final touches.

Refactored a bit of code, also added more validation & error handling in
model classes.