merge with raymond's code