Revert "Removed a heap of unneeded code"

This reverts commit 3a3e85b18f38ee46b0c0517bb25a7160698144a0.