Fixed logic error. Added actual purchase routine.