untidy working version