refactored code; changed template for HPSTR variation