added new version using multi-methods and cleaned old solution using cond instead of if