Refactored code and added bar()