Finalized the solution.

Everything's working now. I pushed myself a bit too much to just get it
done and the code suffers.