Fix quite a few issues