reasonable working code. restructure