switching back to original code, seems to be more stable