LPS-44902 Stop and release the resources after everything has been finished

Updated @migue 's changes resolving conflicts