code refactory, documentation updated