Revision: added requirements section and an optimization