fixed scoping issues