added waitgroup, proper synchronisation