Some cleanup. Adding helper function