Fixed spelling mistake.
Random bug fixes.
Attempt to keep directory structure of files in latex dir.
Subdirectories are now created when needed. Added licence header.
Added some comments.