migrated Prime example from java, could be another good example - but still needs cleanup and optimizations