Add corner tests and optimize functional tests