Refactored some stuff. Added some comments. Changed method signatures for understandability/consistency.