bug fixing, and adding recovery functionality