final submitted v1.0. Various bug fixes.