Fix a lot of bugs and increase coverage