Program seems to work now, needs testing