Removed file opening and closing from inside this function