Code from SENAPP old repositorie, Updated as of june 18 2014