cleaner code, a bit less FP style