Refactored code

Added functions