rewrote some code