Fixed build errors. Merge Qne's code