Fixed bugs, added getSamplePeriod function, cleaned up code