Needs tests
Added test. Fixes #21
Closes resources in test
Merge changes from master