adding beans and refactoring code