Fixed some errors, but not happy with the current state.