final functions added, not much testing yet