implements changes/fixes from
https://github.com/FallenMoonNetwork/CanaryLib/commit/52ba1c6a6274f33bf002be7f99e00bfcf0dc8788