Fixed LDR code to follow always right rule and fixed for some edge cases.