Implemented commented-out stuff from Arian's code