Fix dependency handling bug

Closes #321