partial implementation of stage 2; tested and working