flatten the code a bit