fixed end and clear functions