reorganizado código, resolves #8