Added checks for SL and TP. Refactoring