Moved some functionality into a common file and make simple threshold quantization work