use basename command
remove redundant code