Fix minor bugs and HUE algorithm