working code but need cleanup