Revert "Revert "code seems to work now""

This reverts commit 938136f9ee8e395130e75693c012de7d80f60ca4.