Fixed template double problem and tweaked a lot of stuff