improved based on aki's suggestions