Revert "Revert "malfunctioning code""

This reverts commit b4894d0104310e80e143c366b9ca81d556f95db3.