UPD: Removed deprecated code.
UPD: Reformatted code