Cleaned up inherited code a bit before starting to modularize it