Fixed single precision to work with the one-end trick. The code is messy still