Revert 49b2837..46fafa7

This rolls back to commit 49b2837179d7651f47e914c44f864a925f80f086.
Fixed some silly bugs.