2nd iteration. Now works correctly