Improve some classes; fix bugs