cleaned up gamma function