templated ported for rails and working