Fixed reported bugs, Code optimization, other minor fixes.