Restructure code, add L2 unit tests