Simplified and added a function