Added some code inspired by another project, however may not be applicable.