Add #ifdefs for portability
Fix timestamp calculation
Remove unused code