backend logic almost complete