Well that was quick... Code could be optimized to run much faster, but at the moment it fulfils the assignment