I hope this helps. It's probably not the most efficient code tho.