Optimized code and added tests for layout links