Did more refactoring and addressed several todos.