some code cleanup, and simplification;