several random bug fixes