cast longs correctly