added callbacks and moved logic to modules