Heavily edited code; Did not commit since deadline was near and this had to be finished