rewrote into function