Separate package and tests and fix leak in tests