6/10/13. rewrite code. fixed issues