Finalized syntax and added thorough comments. Needs testing.