Refactoring methods adding more security and flexibility