Code cleanup, fixed getting duration