fixed errors. code not tested tho