Fixes #1 by simplifying code