refactaring and parameter tuning