fixed bad access. -James
fixed logic error. tests passing now. -James