Refactoring a bit and making the code smaller.