added licensing and worked on edge cases