Modify to use xMax/yMax/zMax instead of hardcoding 255/127 all over.