Refactoring almost everything

Bug fixes, injection and security fixes, and just overall
cleanliness.