Added single function for repeating code