added better gaussian fit algorithm (this one actually works)