Split up code
Removed unused code and extracted method