Some fixes, please refer to commit message.