Revert "Re-added most of accidentally deleted code"

This reverts commit e44e9ef478c3354f48cda71a6ee9c5988d85e651.