major refactoring and redisign of code