Minor bug fixes better tests