added window Z ordering support. code refactoring.