Modified some formatting to be more Java idiomatic. Moved parts of methods into own method to better show Single Responsibility (SRP).