refactored and correctioned
added