Improve general quality of code and bug fixes.

This update resolves some major issues with the code, and removes an
unneeded function.