Done! version 3 (still needs comments)