improved layout Python code