First set of bug fixes