Validate slot index before attempting to access it. Fixes #511