Completely refactored the code

Checked the whole code and performed name changes, documentation
expansion/clarification, and what not. Discovered some code that still
needs fixing on that in a jiffy.