Wrote some code. It can probably be replaced with entities...