Added majority of code necessary