source code rewritten and simplified