the code was fully rewritten