Fixed undefined var notice.
Fixed ambiguous SQL column name, added some tests.
Merge branch 'duration-undefined'
Merge branch 'fix-ambiguous-column'