Put more comments in.
Add error handling where it was missing.
Alpha test version for main functionality