WIP: some bug fixes