Added a checking phase before runtime. Improved error checking/diagnostics and code readability. Also added doc comments.