Maybe not optimized, but gets working.