Merging and some bug fixes