moved logic to libs