rewrote main and edited other functions