Implemented #141 & #283 and refactored template functions