Fixes #519 #861 #940 #505 #590 #761 #129 compilation on 64-bit systems