Fixed #6, added relevant test code