Edited from dev branch