refactoring the code. adding namespace support