Improve tests and code style