implement a more elegant code