Refactored a little. I can't believe I forgot about using RegExp in this. Will review and see what else I can do after a fresher mind.
Added in the educated guess method (which will get refactored to make it smarter and quicker).