implemented a more efficient solution