Mass code refactor