Fixed wrong free + added tests