Correction of several bugs and general improvements.