improved and simplified