Added support for finding all factors. Also fixed a bug. Refactored for loop and variables.