Port code from original project