merged startTask and endTask into one method