rewrote the entire code