This could be dealt with better, I went for concise code rather than efficiency of memory/cpu.