cleaned up cache/socket code, added debug stuff

ill remove the debug stuff later when it has been fully tested