refactored code to check if user has sufficient funds