Revert "Revert "bad logic, fixed it now""

This reverts commit 23f3084a79c42c367647ffaba3db121af595728f.
Attempting a rollback