Add various bug fixes