optimized code, minor bug fix.