Further refining and bug fixing.