cleaned up fucntion