formatting and split method

made code easier to read and put some copy-pasted code into a new method