finally fixes #31, closes #14 but very ugly structure