Fixed little bug, refactored a bit, ready for edit