Refactored response formation, implementing conditionals, fixed template extension
Fixed conditions