fully implementing the code [ciroque]