[IMP] Rewritten code
[MERGE] Bug fix + rewritten code