More updates and optimizations to remove duplicate code.
Updates.