Replaced the previous LinkedList with an ArrayDeque for speed purposes
Code reformatted