Rough draft of end sample calculation implemented