Performance improvements on Hibernate, and some bugfixes