Bug fixes + test improvements