better link handling; code simplification