full implementation of test, but crashing (needs to be debugged)