layer refactor. Need expect tests!!!