code refacterd