Some refactoring; ENV defined; some other improvements