improved tests and fixed the scoping issue