BUG : fixed naming typo
BUG : fixed un-defined variable in gray-scale case