commented and cleant up backend code