inlined some statements for conciseness