First version, needs further optimization and configuration