Fixed: combined if blocks
Updated: refactor remove relations block for simplicity and clarity