Use templates instead of ugly writes all over the place