working version, couple of nits