Refactored code and added login with facebook