Source code update - Misc.

Minor bug fixes

Refactoring