Complete rewrite of code, still not working and unfinished